// Copyright 2015-2019 Mail.Ru Group. All Rights Reserved.

package com.ziongame.ZionOneSignal;

import android.app.Activity;
import com.onesignal.OneSignal;
import com.onesignal.OSSubscriptionObserver;
import com.onesignal.OSSubscriptionStateChanges;
import com.onesignal.OneSignal.IdsAvailableHandler;
import com.onesignal.OSNotificationAction;
import com.onesignal.OSNotificationOpenResult;
import com.onesignal.OSNotificationReceivedResult;
import com.onesignal.OSNotification;
import org.json.JSONObject;


public class ZionOneSignal implements OSSubscriptionObserver {
    private static final String ONESIGNAL_APP_ID = "########-####-####-####-############";
    private Activity app_;
    public String onesig_user_id_; 

    public void onAppCreate(Activity app){
        OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
        this.app_ = app;
		OneSignal.init(app,"REMOTE",ONESIGNAL_APP_ID);
        OneSignal.addSubscriptionObserver(this);
    }

    public void onOSSubscriptionChanged(OSSubscriptionStateChanges stateChanges) {
    if (!stateChanges.getFrom().getSubscribed() &&
        stateChanges.getTo().getSubscribed()) {
        this.onesig_user_id_ = stateChanges.getTo().getUserId();

        // new AlertDialog.Builder(this)
        //     .setMessage("You've successfully subscribed to push notifications! "+this.onesig_user_id_)
        //     .show();
        // get player ID
        //stateChanges.getTo().getUserId();
      }
   
      //Log.i("Debug", "onOSSubscriptionChanged: " + stateChanges);
  }
}
